package com.jeremy;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class EasyGoing {
    public static void main(String[] args) throws AWTException {
        String[] beautifulWords = new String[10];
        readText(beautifulWords, "src/com/jeremy/words/beautifulWords.txt");
        Robot r = new Robot();
        r.delay(2000);
        while (true) {
            copyString(beautifulWords);
            pressKey(r);
        }
    }

    public static void readText(String[] beautifulWords, String fileName) {
        int n = 0;
        File file = new File(fileName);
        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            String tmp;
            while ((tmp = br.readLine()) != null) {
                beautifulWords[n++] = tmp;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void copyString(String[] beautifulWords) {
        int a = (int) (Math.random() * 10);
        Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable ts = new StringSelection(beautifulWords[a]);
        cb.setContents(ts, null);

    }

    public static void pressKey(Robot r) {
        r.keyPress(KeyEvent.VK_CONTROL);
        r.keyPress(KeyEvent.VK_V);
        r.keyRelease(KeyEvent.VK_V);
        r.keyRelease(KeyEvent.VK_CONTROL);
        r.delay(100);
        r.keyPress(KeyEvent.VK_ENTER);
        r.keyRelease(KeyEvent.VK_ENTER);
        r.delay(100);
    }
}
